package edu.hebeu.evil.freshmenguide.Activity;

import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.Map;

import edu.hebeu.evil.freshmenguide.Fragment.HanDanViewFragment;
import edu.hebeu.evil.freshmenguide.R;
import edu.hebeu.evil.freshmenguide.View.ZoomOutPageTransformer;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.Activity
 * 时间：16-7-21 上午9:19
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：邯郸美景
 ********************************************/
public class HanDanView extends BaseActivity
{
    private Object[][] res = {{R.drawable.handanview_jingnianghu, "京娘湖", R.string.handanview_jingnianghu}
            , {R.drawable.handanview_wahuanggong, "娲皇宫", R.string.handanview_wahuanggong}
            , {R.drawable.handanview_bowuguan, "邯郸市博物馆", R.string.handanview_bowuguan}
            , {R.drawable.handanview_zhaowangcheng, "赵王城", R.string.handanview_zhaowangcheng}
            , {R.drawable.handanview_xiangtangshan, "响堂山石窟", R.string.handanview_xiangtangshan}};

    private ViewPager viewPager;

    private Adapter adapter;
    private ArrayList<Fragment> fragmentList;

    @Override
    public int setContentView()
    {
        return R.layout.handanview;
    }

    @Override
    public String setToolbarTitle()
    {
        return "邯郸美景";
    }

    @Override
    public void onCreate()
    {
        initView();
        initData();
        setViewPager();
    }

    /**
     * 初始化控件
     */
    private void initView()
    {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
    }

    /**
     * 初始化数据
     */
    private void initData()
    {
        adapter = new Adapter(getSupportFragmentManager());
        fragmentList = new ArrayList<>();


        for (int i = 0; i < res.length; i++)
        {
            fragmentList.add(HanDanViewFragment
                    .newInstance((int) res[i][0]
                            , res[i][1].toString()
                            , (int) res[i][2]));
        }
    }

    /**
     * 设置ViewPager
     */
    private void setViewPager()
    {
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(fragmentList.size());
        viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    }


    private class Adapter extends FragmentStatePagerAdapter
    {
        public Adapter(FragmentManager fm)
        {
            super(fm);
        }

        @Override
        public Fragment getItem(int position)
        {
            return fragmentList.get(position);
        }

        @Override
        public int getCount()
        {
            return fragmentList.size();
        }
    }
}
